package com.key.dwsurvey.action.sysuser;

import com.key.common.base.action.CrudActionSupport;
import com.key.common.base.entity.User;
import com.key.common.utils.web.Struts2Utils;
import com.key.dwsurvey.service.UserManager;
import com.opensymphony.xwork2.ActionSupport;
import net.sf.json.JSONObject;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Namespaces;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import javax.servlet.http.HttpServletRequest;
import com.key.common.utils.web.Struts2Utils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 针对注册action
 * by Hqq
 */
@Namespace("/reg")
@Results({
        @Result(name= UserRegAction.AddUser,location="/WEB-INF/page/content/diaowen-useradmin/reg.jsp",type = Struts2Utils.DISPATCHER),
        @Result(name= CrudActionSupport.RELOAD,location="/login.jsp",type = Struts2Utils.REDIRECT)
})
public class UserRegAction  extends CrudActionSupport<User, String>{
    public final static String AddUser="adduser";
    @Autowired
    private UserManager userManager;
    private String act;

    public String getAct() {
        return act;
    }

    public void setAct(String act) {
        this.act = act;
    }


    //从登陆页跳转
    public String input() throws Exception {
        System.out.println("input（）");
        HttpServletRequest request= Struts2Utils.getRequest();


        request.setAttribute("act",act);
        System.out.println(act);
        return AddUser;
    }

    @Override
    public String save() throws Exception {
        System.out.println("save（）");
        HttpServletRequest request= Struts2Utils.getRequest();
        //这里的entity就是user-进入service层
        userManager.adminSave(entity,null);
        return RELOAD;
    }
    @Override
    protected void prepareModel() throws Exception {
        System.out.println("prepareModel（）");
        entity=userManager.getModel(id);
    }

    public void prepareExecute() throws Exception {
        System.out.println("prepareExecute（）");
        prepareModel();
    }
}
